<?php
	include './includes/connect.php';
	$articoli_fetchati = 0;
	$count = mysql_query("SELECT COUNT(id) FROM articoli");
	$res_count = mysql_fetch_row($count);
	$tot_records = $res_count[0];
	$per_page = 5;
	$tot_pages = ceil($tot_records / $per_page);
	$current_page = (!$_GET['page']) ? 1 : (int)$_GET['page'];
	$primo = ($current_page - 1) * $per_page;
	$query_limit = mysql_query("SELECT * FROM articoli ORDER BY id DESC LIMIT $primo, $per_page");
	while($assoc = mysql_fetch_array($query_limit)) {
		$art_id = $assoc['id'];
		$conta = "SELECT COUNT(com_id) AS conta FROM commenti WHERE com_art = '{$art_id}'";
		$conto = @mysql_query ($conta);
		$tot = @mysql_fetch_array ($conto);
		$articoli_fetchati++;
?>
			<!-- COLONNA CENTRALE-->
			<div id="main">
				<div id="post">
					<div class="post-info">
						<h1 class="post-title"><a href="articolo.php?post=<?=$assoc['titolo'];?>&amp;id=<?=$assoc['id'];?>"><?=$assoc['titolo'];?></a></h1>Postato il <?=$assoc['data'];?> <?php if(isset($_SESSION['utente'])){ ?> | <a href="./revise_post.php?id=<?=$assoc['id'];?>">Modifica</a> <?php } ?>| <a href="articolo.php?post=<?=$assoc['titolo'];?>&amp;id=<?=$assoc['id'];?>">Commenti (<?=$tot['conta'];?>)</a>
<?php
	    $sql = mysql_query("SELECT blog_url FROM info") or die(mysql_error()); 
	    $row = mysql_fetch_array($sql);
	    $url = $row['blog_url'];
?>
					</div>
					<p><?=$assoc['articolo'];?></p>
				</div>
			</div>
<?php
	}
	if ($articoli_fetchati==0){
		echo "Non non sono presenti articoli nel database.";
?>
	<a href="new_post.php">Fai click qui</a> per scriverne uno.
<?php	
	}
?>
			<div id="paginazione"><?php
	include("pagina.php");
	echo "$paginazione";?></div>
